Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResolveInfo::getFieldSelectionWithAliases() => now add instance types and the folded union types to the returned schema. #1681

Merged
merged 3 commits into from
Mar 21, 2025

Conversation

zephyx
Copy link
Contributor

@zephyx zephyx commented Mar 17, 2025

Hi,

After using the ResolveInfo::getFieldSelectionWithAliases() method I needed some additionnal data in order to go through the all schema properly.
So I have updated the method to add:

  • Type instance for each alias level (not set at field level in order to keep the schema simple and avoid breaking changes)
  • Union type management: This allows us to properly go through unions types and retrieve all their respective subfields/args

Before this update, we were able to go through union types but it was unreliable, some fields with the same name in different unioned types could be substituted for others.
Now it's consistent and it allows me in my application to handle a proper infinite level eager loading across the entire schema with unions.

Copy link
Collaborator

@spawnia spawnia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the PHPStan issues, then mark as ready.

@spawnia spawnia marked this pull request as draft March 18, 2025 09:52
zephyx added 2 commits March 19, 2025 00:28
… and the folded union types to the returned schema.
@zephyx
Copy link
Contributor Author

zephyx commented Mar 18, 2025

Hi, thank you for the review.

How should I fix this PHPStan error ?

Cannot access offset 'customA' on (callable(): iterable)|iterable.

On tests/Type/ResolveInfoTest.php

Line 741

Something like this ?

assert(is_array($myCustomWithObjectType->config['fields']), 'ensured by type config');

@spawnia
Copy link
Collaborator

spawnia commented Mar 19, 2025

Hi, thank you for the review.

How should I fix this PHPStan error ?

Cannot access offset 'customA' on (callable(): iterable)|iterable.

On tests/Type/ResolveInfoTest.php

Line 741

Something like this ?

assert(is_array($myCustomWithObjectType->config['fields']), 'ensured by type config');

I would do something like this:

$fields = $myCustomWithObjectType->config['fields'];
assert(is_array($fields), 'ensured by type config');

$myCustomType = $fields['customA'];

@zephyx zephyx marked this pull request as ready for review March 20, 2025 20:31
@spawnia spawnia merged commit 5511603 into webonyx:master Mar 21, 2025
17 checks passed
@spawnia
Copy link
Collaborator

spawnia commented Mar 21, 2025

Thank you, released with https://github.com/webonyx/graphql-php/releases/tag/v15.20.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants